package com.zretc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zretc.dao.InStoreManageMapper;
import com.zretc.entity.Track;
import com.zretc.service.InStoreManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InStoreManageServiceImpl implements InStoreManageService {

    @Autowired
    private InStoreManageMapper mapper;

    @Override
    public PageInfo<Track> findInStoreList(Map<String, Object> param) {
        // 获取参数
        Integer pageNum = (Integer) param.get("pageNum");
        Integer pageSize = (Integer) param.get("pageSize");
        String opCode = (String) param.get("opCode");
        String houseName = (String) param.get("houseName");
        String orderId = (String) param.get("orderId");
        // 开始分页
        PageHelper.startPage(pageNum, pageSize);
        // 调用dao层方法，查询入库信息
        Map<String, Object> map = new HashMap<>();

        map.put("opCode",opCode);

        if ("".equals(houseName) || houseName == null){
            map.put("houseName",null);
        }else {
            map.put("houseName","%"+houseName+"%");
        }

        if ("".equals(orderId) || orderId == null){
            map.put("orderId",null);
        }else {
            map.put("orderId",orderId);
        }

        List<Track> inStoreList = mapper.findInStoreList(map);
        // 包装
        PageInfo<Track> pageInfo = new PageInfo<>(inStoreList);
        return pageInfo;
    }

    @Override
    public int deleteInStoreByOrderId(String orderId) {

        return mapper.deleteInStoreByOrderId(orderId);
    }
}
